package com.xgc.book.bookserver.controller;


import com.xgc.book.bookserver.bean.BookCatalogBean;
import com.xgc.book.bookserver.service.BookCatalogService;
import com.xgc.book.bookserver.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 图书章节表 前端控制器
 * </p>
 *
 * @author wrz
 * @since 2023-11-20
 */
@RestController
@RequestMapping("/book/catalog")
public class BookCatalogController {
    @Autowired
    private BookCatalogService bookCatalogService;

    @GetMapping("/page")
    public ResultJson getPage(int page, int limit, BookCatalogBean bookCatalogBean) {
        return bookCatalogService.getPage(page, limit, bookCatalogBean);
    }

    @GetMapping("/info/{id}")
    public ResultJson getByBookId(@PathVariable Integer id) {
        return ResultJson.ok(bookCatalogService.getById(id));
    }

    @PostMapping(value = {"/update", "/status/info", "/status/catalog", "/order"})
    public ResultJson update(@RequestBody BookCatalogBean bookCatalogBean) {
        bookCatalogService.saveOrUpdate(bookCatalogBean);
        return ResultJson.ok();
    }

    @DeleteMapping("/delete/{id}")
    public ResultJson delete(@PathVariable Integer id) {
        bookCatalogService.removeById(id);
        return ResultJson.ok();
    }

}

